<?php
header('Content-Type: text/xml');
$dom = new DOMDocument();
$link = mysql_connect("localhost","root","1234");
mysql_select_db("mobile", $link) or die("Could not find database.");

$result = mysql_query("SELECT * FROM itemlist ") or die("Data not found.");

////////// Create the root  element
$itemlist = $dom->createElement('itemlist');
$dom->appendChild($itemlist);

////////// Create the child  element

while ($row = mysql_fetch_array($result)) 
{
	$item = $dom->createElement('item');
	$itemlist->appendChild($item); 
	//$order->setAttribute("type","it");

	$id = $dom->createElement('id');
	$item->appendChild($id);
	$idtext = $dom->createTextNode($row[0]);
	$id->appendChild($idtext);

	$itemname = $dom->createElement('itemname');
	$item->appendChild($itemname);
	$itemnametext = $dom->createTextNode($row[1]);
	$itemname->appendChild($itemnametext);
	
	$picture= $dom->createElement('picture');
	$item->appendChild($picture);
	$picturetext = $dom->createTextNode($row[2]);
	$picture->appendChild($picturetext);
	
	$category = $dom->createElement('category');
	$item->appendChild($category);
	$categorytext = $dom->createTextNode($row[3]);
	$category->appendChild($categorytext);

	$price = $dom->createElement('price');
	$item->appendChild($price);
	$pricetext = $dom->createTextNode(($row[4]));
	$price->appendChild($pricetext);

}



$xmlString = $dom->saveXML();
$dom->save("item.xml");
$xmlString = ltrim(substr($xmlString, strpos($xmlString,'?'.'>')+2));
echo $xmlString;



?>